<?php
declare (strict_types=1);

namespace app\exam\model\admin;

use app\common\model\BaseModel;
use app\common\logic\category\Category;

/**
 * 知识点
 */
class QuestionPoint extends BaseModel
{

    /**
     * 表名
     * @var string
     */
    protected $name = 'exam_question_point';


    /**
     * 全局查询范围
     * @var [type]
     */
    protected $globalScope = ['mhm'];

    protected $type = [
        'category'         => 'string',
        'fullcategorypath' => 'array'
    ];

    /**
     * 限制机构条件
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-06-16
     * @param    [type]                         $query [description]
     * @return   [type]                                [description]
     */
    public function scopeMhm($query)
    {
        // 机构
        $query->where('mhm_id', request()->mhm_id);
    }

    /**
     * 获取分类全路径名称
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2022-03-17
     * @param  [type] $v    [description]
     * @param  [type] $data [description]
     * @return [type]       [description]
     */
    public function getCategoryStrAttr($v, $data)
    {
        return $data['category'] ? app(Category::class)->parseTitle($data['category'], 3) : '';
    }

    /**
     * 新增数据事件
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-03-14
     * @return   string
     */
    public static function onBeforeInsert($point)
    {
        // 机构
        $point->mhm_id = $point->getAttr('mhm_id') ?: request()->mhm_id;
    }

    /**
     * 成功创建之后
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-06-17
     */
    public static function onAfterInsert($category)
    {
    }

    /**
     * 成功修改之后
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-06-17
     */
    public static function onAfterUpdate($category)
    {
    }

    /**
     * 成功删除之后
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-06-17
     */
    public static function onAfterDelete($category)
    {
    }
}
